package com.sprucetec.live.service.impl;

import com.sprucetec.live.common.webcontext.LoginUserContext;
import com.sprucetec.live.entity.LiveVideoServerDetail;
import com.sprucetec.live.enums.DeleteStatusEnum;
import com.sprucetec.live.mapper.LiveVideoServerDetailMapper;
import com.sprucetec.live.service.LiveVideoServerDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.util.Date;
import java.util.List;

/**
 * @author chenkai
 * @date 2020/4/1 11:02 上午
 * @description:
 */
@Slf4j
@Service("liveVideoServerDetailService")
public class LiveVideoServerDetailServiceImpl implements LiveVideoServerDetailService {

    @Autowired
    private LiveVideoServerDetailMapper liveVideoServerDetailMapper;

    @Override
    public void batchInsert(List<LiveVideoServerDetail> list) {
        liveVideoServerDetailMapper.batchInsert(list);
    }

    @Override
    public void deleteServerDetail(Long liveVideoId) {
        Example example = new Example(LiveVideoServerDetail.class);
        example.createCriteria().andEqualTo("liveVideoId", liveVideoId);

        LiveVideoServerDetail videoServerDetail = new LiveVideoServerDetail();
        videoServerDetail.setIsDeleted(DeleteStatusEnum.DELETED.getCode());
        videoServerDetail.setUpdateTime(new Date());
        videoServerDetail.setUpdateUserCode(LoginUserContext.getUser().getUid());
        videoServerDetail.setUpdateUserName(LoginUserContext.getUser().getName());
        liveVideoServerDetailMapper.updateByExampleSelective(videoServerDetail, example);
    }

    @Override
    public List<LiveVideoServerDetail> getServerDetailList(Long liveVideoId) {
        Example example = new Example(LiveVideoServerDetail.class);
        example.createCriteria().andEqualTo("liveVideoId", liveVideoId).andEqualTo("isDeleted", DeleteStatusEnum.VALID.getCode());
        return liveVideoServerDetailMapper.selectByExample(example);
    }
}
